


(async () => {
  var mongoose = require('mongoose');
  const Template = require('./schema/Template')
  const Menu = require('./schema/Menu')
  mongoose.connect('mongodb://user1:123qwe@111.231.55.85:27017/hospital_test', { useNewUrlParser: true });
  // Template.find((err, res) => {
  //   console.log(res)
  // })
  // let menu = await new Menu({name: 'menuxxx'}).save()
  // let menus = await Menu.find({ name: 'Vip' })
  // let menus = await Menu.find({ name: ['menuxxx', 'Vip'] })
  // console.log(menus)
  // var Kitten = mongoose.model('Kitten', kittySchema);

  // var silence = new Kitten({ name: 'Silence' });

  // silence.save()
  /*
  */
 let chiefComplaint = {
    data: [
      {
        part: ['C.100.100067'],        
        symptom: 'C.101.100001',
        character: 'C.102.100001',
        level: 'C.103.tiny',
        time: 35,
        unit: 'C.105.day',        
        chosen: true
      },
      {
        part: ['C.100.100064'], 
        symptom: 'C.101.100044',
        character: 'C.102.100005',
        level: 'C.103.serious',
        time: 5,
        unit: 'C.105.year',
        chosen: true,
        follow: [
          {
            symptom: 'C.101.100028'
          }
        ]
      },
      {
        part: ['C.100.100035'],
        symptom: 'C.101.100050',
        character: 'C.102.100003',
        level: 'C.103.light',        
        time: 2,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100051'],
        symptom: 'C.101.100017',
        character: 'C.102.100001',
        level: 'C.103.tiny',
        time: 8,
        unit: 'C.105.month',
        chosen: true
      },
      {
        part: ['C.100.100068'],
        symptom: 'C.101.100015',
        character: 'C.102.100002',
        level: 'C.103.medium',
        time: 6,
        unit: 'C.105.week',
        chosen: true
      },
      {
        part: ['C.100.100038'],        
        symptom: 'C.101.100046',
        character: 'C.102.100004',
        level: 'C.103.light',
        time: 50,
        unit: 'C.105.hour',        
        chosen: true
      },
      {
        part: ['C.100.100001'], 
        symptom: 'C.101.100050',
        character: 'C.102.100010',
        level: 'C.103.medium',
        time: 6,
        unit: 'C.105.week',
        chosen: true,
        follow: [
          {
            symptom: 'C.101.100028'
          }
        ]
      },
      {
        part: ['C.100.100014'],
        symptom: 'C.101.100044',
        character: 'C.102.100001',
        level: 'C.103.light',        
        time: 12,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100022'],
        symptom: 'C.101.100058',
        character: 'C.102.100011',
        level: 'C.103.serious',
        time: 3,
        unit: 'C.105.year',
        chosen: true
      },
      {
        part: ['C.100.100029'],
        symptom: 'C.101.100012',
        character: 'C.102.100014',
        level: 'C.103.serious',
        time: 4,
        unit: 'C.105.day',
        chosen: true
      },
      {
        part: ['C.100.100019'],
        symptom: 'C.101.100012',
        character: 'C.102.100005',
        level: 'C.103.medium',
        time: 5,
        unit: 'C.105.day',
        chosen: true
      },
      {
        part: ['C.100.100066'],
        symptom: 'C.101.100001',
        character: 'C.102.100017',
        level: 'C.103.medium',
        time: 8,
        unit: 'C.105.week',
        chosen: true
      }        
    ],
    mainType: [
      // {
      //   name: '肺炎',
      //   type: ['病毒性肺炎','真菌性肺炎','细菌性肺炎','支原体肺炎','衣原体肺炎']
      // }
    ],
  }
  let patientInfo = {
    patientName: {
      label: '姓名',
      value: null,
      chosen: true
    },
    medicareId: {
      label: '医保卡号',
      value: null,
      chosen: true
    },
    sex: {
      label: '性别',
      value: null,
      chosen: true
    },
    age: {
      label: '年龄',
      value: null,
      chosen: true
    },
    temperature: {
      label: '体温',
      value: null,
      chosen: true
    },
    sbp: {
      label: '收缩压',
      value: null,
      chosen: true
    },
    dbp: {
      label: '舒张压',
      value: null,
      chosen: true
    },
    heartRate: {
      label: '心率',
      value: null,
      chosen: true
    },
    weight: {
      label: '体重',
      value: null,
      chosen: false
    },
    height: {
      label: '身高',
      value: null,
      chosen: false
    },
    bmi: {
      label: 'BMI指数',
      value: null,
      chosen: false
    },
    breath: {
      label: '呼吸',
      value: null,
      chosen: false
    },
    marriage: {
      label: '婚孕',
      value: null,
      chosen: false
    },
    pulse: {
      label: '脉搏',
      value: null,
      chosen: false
    },
    spo2: {
      label: '氧饱和度',
      value: null,
      chosen: false
    }
  }
  let data = {
    name: '肺炎1型',
    templateOwner: 'hospital',
    remark: '备注zzzzz',
    patientInfo: patientInfo,
    chiefComplaint: chiefComplaint,
    HPI: {
      situation: {
        ifNull: false,
        date: '2017-12-13',
        cause: ['D.101.100002', 'D.101.100003']
      },
      treatment: {
        ifNull: false,
        data: [
          {
            display: 'D.102.100001',
            method: 'D.104.100001',
            measure: 'D.105.100001',
            effect: 'D.106.100001',
            duration: 1,
            unit: 'C.105.month'
          }
        ]
      },
      unusual: {
        ifNull: false
      }
    },
    pastHistory: {
      personal: {
        ifNull: false,
        data: ['吸烟', '熬夜', '精神创伤']
      },
      family: {
        ifNull: false,
        data: [{
          disease: '100010',
          sibship: '100002',
          age: '0'
        }]
      },
      surgery: [
        {
          ifNull: false,
          data: [{
            name: '手术名称',
            ID: 'IDXXX',
            hospital: '浙江省第一人民医院',
            dateTime: '2014-11-16'
          }]
        }
      ],
      allergic: {
        ifNull: false,
        data: [{
          source: '100001',
          reaction: '100001',
          level: '100001'
        }]
      },
      menstrual: {
        ifNull: false,
        firstAge: 12,
        cycle: 27,
        duration: 27,
        lastDate: '2018-01-01',
        endDate: '2018-01-01',
        endAge: 50
      },
      chronic: {
        ifNull: false,
        data: [{
          disease: '100008',
          duration: 3,
          durationUnit: 'quarter',
          level: '100003'
        }]
      }
    },
    PE: {
      items: {
        small: [],
        big: []
      },
      values: '{}'
    },
    checkout: {
      checked: [],
      checking: [],
      testing: []
    },
  }
  data.templateOwner = '666001'
  data.templateOwnerName = '消化内科主任'
  data.templateOwnerType = 'doctor'
  data.name = '肺炎1型-自己'
  await new Template(data).save()
  data.templateOwner = '810001'
  data.templateOwnerName = '消化内科'
  data.templateOwnerType = 'dept'
  data.name = '肺炎1型-科室'
  await new Template(data).save()
  data.templateOwner = '501'
  data.templateOwnerName = '消化内科医疗组1'
  data.templateOwnerType = 'group'
  data.name = '肺炎1型-医疗组'
  await new Template(data).save()
  data.templateOwner = 'hospital'
  data.templateOwnerName = '浙江省人民医院'
  data.templateOwnerType = 'hospital'
  data.name = '肺炎1型-医院'
  await new Template(data).save()
  // let tempMine = await Template.find({ templateOwner: '804002' })
  // let tempDept = await Template.find({ templateOwner: '804' })
  // let tempHospital = await Template.find({ templateOwner: 'hospital' })
  // console.log(tempMine)
  // console.log(tempDept)
  // console.log(tempHospital)
  // let temp = await Template.findById('5c245d02a4d3da02a4f8ec7b')
  // console.log(temp)
  process.exit(0)
})()